﻿using IoTClient.Enums;
using Newtonsoft.Json;
using System.ComponentModel;
using System.Xml.Serialization;

namespace IoTClient
{
    /// <summary>
    /// 变量
    /// </summary>
    public class Variable
    {
        /// <summary>
        /// 变量名子
        /// </summary>
        [JsonProperty("变量名字"), DisplayName("变量名"), Category("变量信息")] public string Name { get; set; } = "Name";

        /// <summary>
        /// 变量地址
        /// </summary>
        [JsonProperty("变量地址"), DisplayName("地址"), Category("变量信息")] public string Address { get; set; } = "MB0";

        /// <summary>
        /// 变量当前值
        /// </summary>
        [XmlIgnore, Browsable(false)] public object Value { get; set; }

        /// <summary>
        /// 数据类型
        /// </summary>
        [JsonProperty("数据类型"), DisplayName("数据类型"), Category("变量信息")] public DataTypeEnum DataType { get; set; } = DataTypeEnum.Byte;

        /// <summary>
        /// 读写权限
        /// </summary>
        [JsonProperty("读写权限"), DisplayName("读写权限"), Category("变量信息")] public WriteOrRead WriteOrRead { get; set; } = WriteOrRead.ReadAndWrite;

        #region MyRegion

        /// <summary>
        /// 允许报警
        /// </summary>
        [XmlIgnore, Browsable(false)]
        public bool AlarmEnable { get; set; } = false;

        /// <summary>
        /// 允许记录
        /// </summary>

        [JsonProperty("记录允许"), DisplayName("记录允许"), DefaultValue(false), Category("记录允许")]
        public bool ArchiveEnable { get; set; } = false;

        /// <summary>
        /// 设定限制允许:开启后超过这个范围的值不能被设定
        /// </summary>
        [XmlElement("是否开启写入范围限定"), DisplayName("设定值限定允许"), DefaultValue(false), Category("设定值限定允许")]
        public bool SetLimitEnable { get; set; } = false;

        /// <summary>
        /// 允许写入最大值
        /// </summary>
        [XmlElement("允许写入最大值"), DisplayName("允许写入最大值"), DefaultValue(100f), Category("设定值限定允许")]
        public float SetLimitMax { get; set; } = 100f;

        /// <summary>
        /// 允许写入最小值
        /// </summary>

        [XmlElement("允许写入最小值"), DisplayName("允许写入最小值"), DefaultValue(0f), Category("设定值限定允许")]
        public float SetLimitMin { get; set; } = 0f;

        /// <summary>
        /// 离散报警:分为上升沿和下降沿;为true表示上升沿报警;false表示下降沿报警
        /// </summary>
        [XmlElement("上升沿Or下降沿报警"), DisplayName("上升沿Or下降沿报警"), DefaultValue(false), Category("离散报警")]
        public bool DiscreteAlarmType { get; set; } = false;

        /// <summary>
        /// 上升沿离散报警缓存值
        /// </summary>
        [XmlIgnore, Browsable(false)] public bool RiseCacheValue { get; set; } = false;

        /// <summary>
        /// 下降沿离散报警缓存值
        /// </summary>
        [XmlIgnore, Browsable(false)] public bool FallCacheValue { get; set; } = true;

        /// <summary>
        /// 离散报警优先级
        /// </summary>
        [XmlElement("离散报警优先级"), DisplayName("离散报警优先级"), Category("离散报警")]
        public int DiscreteAlarmPriority { get; set; } = 0;

        /// <summary>
        /// 离散报警说明
        /// </summary>
        [XmlElement("离散报警说明"), DisplayName("离散报警说明"), Category("离散报警")]
        public string DiscreteAlarmNote { get; set; } = "离散报警说明";

        /// <summary>
        /// 低低报警允许
        /// </summary>
        [XmlElement("超低报警允许"), DisplayName("超低报警允许"), Category("超低报警")] public bool LLowAlarmEnable { get; set; } = false;

        /// <summary>
        /// 低低报警值
        /// </summary>
        [XmlElement("超低报警设定值"), DisplayName("超低报警设定值"), Category("超低报警")] public float LLowAlarmSetValue { get; set; } = 0f;

        /// <summary>
        /// 低低报警缓存值
        /// </summary>
        [XmlIgnore, Browsable(false)] public float LLowCacheValue { get; set; } = float.MaxValue;

        /// <summary>
        /// 低低报警优先级
        /// </summary>
        [XmlElement("超低报警优先级"), DisplayName("超低报警优先级"), Category("超低报警")] public int LLowAlarmPriority { get; set; } = 0;

        /// <summary>
        /// 低低报警说明
        /// </summary>

        [XmlElement("超低报警说明"), DisplayName("超低报警说明"), Category("超低报警")]
        public string LLowAlarmNote { get; set; } = "超低报警说明";

        /// <summary>
        /// 低报警允许
        /// </summary>
        [XmlElement("低报警允许"), DisplayName("低报警允许"), Category("低报警")] public bool LowAlarmEnable { get; set; } = false;

        /// <summary>
        /// 低报警值
        /// </summary>
        [XmlElement("低报警设定值"), DisplayName("低报警设定值"), Category("低报警")] public float LowAlarmSetValue { get; set; } = 0f;

        /// <summary>
        /// 低报警缓存值
        /// </summary>
        [XmlIgnore, Browsable(false)] public float LowCacheValue { get; set; } = float.MaxValue;

        /// <summary>
        /// 低报警优先级
        /// </summary>
        [XmlElement("低报警优先级"), DisplayName("低报警优先级"), Category("低报警")] public int LowAlarmPriority { get; set; } = 0;

        /// <summary>
        /// 低报警说明
        /// </summary>

        [XmlElement("低报警说明"), DisplayName("低报警说明"), Category("低报警")] public string LowAlarmNote { get; set; } = "低报警说明";

        /// <summary>
        /// 高报警允许
        /// </summary>
        [XmlElement("高报警允许"), DisplayName("高报警允许"), Category("高报警")] public bool HighAlarmEnable { get; set; } = false;

        /// <summary>
        /// 高报警设定值
        /// </summary>
        [XmlElement("高报警设定值"), DisplayName("高报警设定值"), Category("高报警")] public float HighAlarmSetValue { get; set; } = 0f;

        /// <summary>
        /// 高报警缓存值
        /// </summary>
        [XmlIgnore, Browsable(false)] public float HighCacheValue { get; set; } = float.MinValue;

        /// <summary>
        /// 高报警优先级
        /// </summary>
        [XmlElement("高报警优先级"), DisplayName("高报警优先级"), Category("高报警")] public int HighAlarmPriority { get; set; } = 0;

        /// <summary>
        /// 高报警说明
        /// </summary>
        [XmlElement("高报警说明"), DisplayName("高报警说明"), Category("高报警")] public string HighAlarmNote { get; set; } = "高报警说明";

        /// <summary>
        /// 高高报警允许
        /// </summary>
        [XmlElement("超高报警允许"), DisplayName("超高报警允许"), Category("超高报警")] public bool HHighAlarmEnable { get; set; } = false;

        /// <summary>
        /// 高高报警值
        /// </summary>
        [XmlElement("超高报警设定值"), DisplayName("超高报警设定值"), Category("超高报警")] public float HHighAlarmSetValue { get; set; } = 0f;

        /// <summary>
        /// 高高报警缓存值
        /// </summary>
        [XmlIgnore, Browsable(false)] public float HHighCacheValue { get; set; } = float.MinValue;

        /// <summary>
        /// 高高报警优先级
        /// </summary>
        [XmlElement("超高报警优先级"), DisplayName("超高报警优先级"), Category("超高报警")] public int HHighAlarmPriority { get; set; } = 0;

        /// <summary>
        /// 高高报警说明
        /// </summary>
        [XmlElement("超高报警说明"), DisplayName("超高报警说明"), Category("超高报警")] public string HHighAlarmNote { get; set; } = "高高报警说明";

        /// <summary>
        /// 归档周期:多久记录一次
        /// </summary>
        [XmlElement("记录周期"), DisplayName("记录周期"), Category("记录允许"), Description("归档周期:多久记录一次")]
        public int ArchivePeriod { get; set; }

        /// <summary>
        /// 变量描述
        /// </summary>
        [XmlElement("变量描述"), DisplayName("变量描述"), Category("变量信息")] public string Description { get; set; } = "这是一个什么样的变量";

        #endregion MyRegion
    }
}